home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Disk / Directory / print.c < prev    next >
Encoding:
Text File  |  1993-02-03  |  3.2 KB  |  178 lines  |  [TEXT/KAHL]

  1. //-- Print.c
  2.  
  3. // Handle printing this window.
  4.  
  5. #include <PrintTraps.h>
  6.  
  7. #include <stdio.h>
  8. #include "struct.h"
  9.  
  10.  
  11. THPrint hPrint = nil;
  12. WindowPtr statusWindow;
  13. char printMsg[] = "Now printing.  To halt, hit control-'.'; this seems to do the trick...";
  14.  
  15.  
  16. //-- OpenWarning
  17.  
  18. // Open a warning window in the center of the screen.
  19.  
  20. OpenWarning()
  21. {
  22.     GrafPtr foo;
  23.     int x,y;
  24.     Rect r;
  25.  
  26.     GetWMgrPort(&foo);
  27.     r = foo->portRect;
  28.     x = (r.right - r.left - 200) / 2;
  29.     y = (r.bottom - r.top - 100) / 2;
  30.     r.top = y;
  31.     r.bottom = r.top + 100;
  32.     r.left = x;
  33.     r.right = r.left + 200;
  34.     statusWindow = NewWindow(nil,&r,"",1,1,(char *)-1,0,0L);
  35.     SetPort(statusWindow);
  36.     TextFont(0);
  37.     TextSize(12);
  38.     r.bottom -= r.top;
  39.     r.top = 0;
  40.     r.right -= r.left;
  41.     r.left = 0;
  42.     InsetRect(&r,8,8);
  43.     TextBox(printMsg,(long)strlen(printMsg),&r,0);
  44. }
  45.  
  46.  
  47. //-- CloseWarning
  48.  
  49. // Close print warning.
  50.  
  51. CloseWarning()
  52. {
  53.     DisposeWindow(statusWindow);
  54. }
  55.  
  56.  
  57.  
  58. //-- PrintStl
  59.  
  60. // Print style dialog.
  61.  
  62. PrintStl()
  63. {
  64.     PrOpen();
  65.     if (hPrint == nil) 
  66.     {
  67.         hPrint = (THPrint)NewHandle(sizeof(TPrint));
  68.         if (hPrint == nil) return;
  69.         PrintDefault(hPrint);
  70.     }
  71.     
  72.     PrStlDialog(hPrint);
  73.     PrClose();
  74. }
  75.  
  76.  
  77.  
  78. //-- PrintJob
  79.  
  80. // Print job dialog.
  81.  
  82. PrintJob()
  83. {
  84.     struct DrawWindow *w;
  85.     long len;
  86.     long x;
  87.     struct DirectData *ptr;
  88.     long pagenum;
  89.     TPPrPort pPrPort;
  90.     TPrStatus myPrStatus;
  91.     short ind;
  92.     short xx;
  93.     Rect r;
  94.     short pageNum;
  95.     char buffer[64];
  96.  
  97.     if (nil == (w = (struct DrawWindow *)FrontWindow())) return;
  98.     if (w->w.windowKind != WK_PLAN) return;
  99.     
  100.     PrOpen();
  101.     if (hPrint == nil) {
  102.         hPrint = (THPrint)NewHandle(sizeof(TPrint));
  103.         if (hPrint == nil) return;
  104.         PrintDefault(hPrint);
  105.     }
  106.     
  107.     if (PrJobDialog(hPrint))
  108.     {
  109.         OpenWarning();
  110.         
  111.         HLock(w->data);
  112.         ptr = *(w->data);
  113.         len = GetHandleSize(w->data) / sizeof(struct DirectData);
  114.         pPrPort = PrOpenDoc(hPrint,nil,nil);
  115.         SetPort(pPrPort);
  116.         r = (**hPrint).prInfo.rPage;                /* Page rectangle */
  117.         r.bottom -= 15;
  118.         x = 0;
  119.         pageNum = 1;
  120.         while (x < len) {
  121.             if (PrError() == noErr) {
  122.                 PrOpenPage(pPrPort,nil);
  123.                 
  124.                 TextFont(4);
  125.                 TextSize(9);
  126.                 sprintf(buffer,"Page %d",pageNum);
  127.                 CtoPstr(buffer);
  128.                 MoveTo(r.right - 20 - StringWidth(buffer),25);
  129.                 DrawString(buffer);
  130.                 
  131.                 sprintf(buffer,"Directory listing of %s",w->vName);
  132.                 CtoPstr(buffer);
  133.                 MoveTo(r.left + 20, 25);
  134.                 DrawString(buffer);
  135.                 
  136.                 MoveTo(r.left + 10, 28);
  137.                 LineTo(r.right - 10, 28);
  138.                 MoveTo(r.left + 10, 30);
  139.                 LineTo(r.right - 10, 30);
  140.  
  141.                 xx = 40 + r.top;
  142.                 if (PrError() == noErr) {
  143.                     while ((xx < r.bottom) && (x < len)) {
  144.                         for (ind = 0; ind < ptr[x].indent; ind++) {
  145.                             MoveTo(ind*12+25,xx-10);
  146.                             Line(0,12);
  147.                         }
  148.     
  149.                         MoveTo(ptr[x].indent*12+20,xx);
  150.                         DrawString(ptr[x].data);
  151.     
  152.                         if (ptr[x].auxdata[0] != '\0') {
  153.                             MoveTo(ptr[x].indent*12+25+StringWidth(ptr[x].data),xx);
  154.                             LineTo(305,xx);
  155.                             MoveTo(370 - StringWidth(ptr[x].auxdata),xx);
  156.                             DrawString(ptr[x].auxdata);
  157.                             
  158.                             MoveTo(390,xx);
  159.                             DrawString(ptr[x].auxdata2);
  160.                         }
  161.                         x++;
  162.                         xx += 12;
  163.                     }
  164.                 }
  165.                 PrClosePage(pPrPort);
  166.                 pageNum++;
  167.             } else break;
  168.         }
  169.         PrCloseDoc(pPrPort);
  170.         if (((**hPrint).prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr)) {
  171.             PrPicFile(hPrint,nil,nil,nil,&myPrStatus);
  172.         }
  173.  
  174.         CloseWarning();
  175.     }
  176.     PrClose();
  177. }
  178.